import 'package:flutter/material.dart';
import 'package:yp/config/config.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../helper.dart';
import 'logic.dart';
import 'state.dart';

class UserCreatePage extends StatelessWidget {
  final UserCreateLogic logic = Get.put(UserCreateLogic());
  final UserCreateState state = Get.find<UserCreateLogic>().state;

  @override
  Widget build(BuildContext context) {
    state.mobileNum = Get.parameters["moile"] ?? "1" ?? 1;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Config.mainColor,
        title: Text(
          "注册会员",
          style: TextStyle(
            color: Colors.white,
            fontSize: 32.sp,
          ),
        ),
        centerTitle: true,
        elevation: 0,
      ),
      body: GetBuilder<UserCreateLogic>(
          builder: (logic) {
            return Column(
              children: [
                Expanded(
                  child: Column(
                      children: [
                        Container(
                          width: 750.w,
                          padding: EdgeInsets.symmetric(vertical: 40.w,horizontal: 40.w,),
                          decoration: BoxDecoration(
                            color: Colors.white,
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                "请输入验证码",
                                style: TextStyle(
                                  color: Color(0xffCCCCCC),
                                  fontSize: 26.sp,
                                ),
                              ),
                              Container(
                                height: 110.w,
                                alignment: Alignment.centerLeft,
                                margin: EdgeInsets.only(bottom: 10.w),
                                child: TextField(
                                  controller: state.controller,
                                  style: TextStyle(
                                    fontSize: 30.sp,
                                    height: 1.5,
                                  ),
                                  textAlignVertical: TextAlignVertical.center,
                                  maxLines: 1,
                                  decoration: InputDecoration(
                                    isDense: true,
                                    contentPadding: EdgeInsets.symmetric(vertical: 30.w),
                                    prefixIconConstraints: BoxConstraints(
                                      maxWidth: 60.w,
                                      minWidth: 60.w,
                                    ),
                                    suffixIconConstraints: BoxConstraints(
                                      maxWidth: 150.w,
                                      minWidth: 150.w,
                                    ),
                                    suffixIcon:InkWell(
                                      onTap: () {
                                        if (logic.state.seconds > 0 && logic.state.seconds < 60) {
                                          return;
                                        }
                                        logic.sendSms();
                                      },
                                      child: Align(
                                        alignment: Alignment.centerRight,
                                        child: Container(
                                          width: 150.w,
                                          height: 56.w,
                                          decoration: BoxDecoration(
                                            color: Color(0xffcccccc),
                                          ),
                                          child:Center(
                                            child: Text(
                                              logic.state.verifyStr,
                                              style: TextStyle(
                                                fontSize: 24.sp,
                                                fontWeight: FontWeight.w400,
                                                color: Colors.white,
                                              ),
                                              textAlign: TextAlign.left,
                                            ),
                                          ),
                                        ),
                                      ),
                                    ),
                                    hintText: '',
                                    hintStyle: TextStyle(
                                      fontSize: 30.sp,
                                      color: Color(0xffbbbbbb),
                                    ),
                                    enabledBorder: UnderlineInputBorder(
                                      borderSide: BorderSide(
                                        color: Color(0xffdddddd),
                                      ),
                                    ),
                                    focusedBorder: UnderlineInputBorder(
                                      borderSide: BorderSide(
                                        color: Config.mainColor,
                                      ),
                                    ),
                                    border: UnderlineInputBorder(
                                      borderSide: BorderSide(
                                        color: Color(0xffdddddd),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              SizedBox(height:50.w),
                              GestureDetector(
                                onTap: () {
                                  String code = state.controller.text;
                                  if(code.isEmpty){
                                    toast("请输入验证码");
                                    return;
                                  }
                                  logic.verifyRegistration();
                                },
                                child:Center(
                                  child: Container(
                                    width: 640.w,
                                    height: 90.w,
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(
                                        Radius.circular(45),
                                      ),
                                      color: Config.mainColor,
                                    ),
                                    child: Center(
                                      child: Text(
                                        "立即验证",
                                        style: TextStyle(
                                          fontSize: 36.sp,
                                          color: Colors.white,
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                      ]
                  ),
                ),
              ],
            );
          }),
    );
  }
}
